package Sequence;

public class Test0718 {
}

class Solution0178_1 {
    public int findLength(int[] nums1, int[] nums2) {
        int length1 = nums1.length;
        int length2 = nums2.length;

        int ans=0;
        int[][] dp = new int[length1+1][length2+1];

        for (int i = 1; i <= length1; i++) {
            int num1 = nums1[i - 1];
            for (int j = 1; j <= length2; j++) {
                int num2 = nums2[j - 1];

                if (num1 == num2) dp[i][j] = dp[i - 1][j - 1] + 1;
                else dp[i][j] = 0;

                ans = Math.max(ans, dp[i][j]);
            }
        }

        return ans;
    }
}
